document.querySelector('#btn-register').addEventListener('click', async function () {
    const data = serialize(document.querySelector('.register-form'), { hash: true, empty: true })
    const { username, password } = data
    if (username == '' || password == '') return showToast('用户名或密码不能为空')
    if (username.length < 8 || username.length > 30 || password.length < 6 || password.length > 30) return showToast('用户名8-30，密码6-30')
    try {
        const res = await axios.post('/register', data)
        showToast(res.message)
    } catch (error) {
        // dir 展开error对象 看对象细节
        // console.dir(error)
        showToast(error.response.data.message)
    }
}) 